package com.example.zz.example.datastructures;


/**
 * DESCRIPTION:
 * AUTHOR: zz
 * BLOG: https://blog.scdn.net/zhangzhuo1024
 * DATE: 2022/9/24
 **/
public class StringDemo {

    public static void main(String[] args) {

        char[] chars = {'q', 'w', 'e'};
        String str = "abc bd ";
        int length = str.length();//字符串长度用length()
        int length1 = chars.length;//数组、字符串数组长度用length
        System.out.println(length1 + "  " + length);
        //3  7

        //增
        System.out.println("===增===");
        String str2 = new String(chars);
        String str3 = str + str2;
        System.out.println(str3);// abcdqwe  字符串拼接
        //abc bd qwe

        String charu = "asdf";
        StringBuffer sb = new StringBuffer(charu);
        StringBuffer aaa = sb.insert(3, "a3");//字符串插入要用StringBuffer
        System.out.println(aaa);
        //asda3f

        //删
        System.out.println("===删===");
        String shan = "shanchuzifuchuan";
        String substring = shan.substring(3);
        String substring1 = shan.substring(3, 7);
        System.out.println(substring + "  " + substring1);//nchuzifuchuan  nchu
        String[] us = shan.split("u");
        for (String u : us) {
            System.out.println(u);
        }
//        shanch
//        zif
//        ch
//        an

        //  String[] us1 = shan.split("u", 2);
        // 其中regex为分割正则表达式，limit为分割次数限制，如 String str = ",," 调用 split(","),返回一个空数组，长度为 0
//        String douhao = ",,";
//        String[] split = douhao.split(",", 3);
//        for (String s : split) {
//            System.out.println(s);
//        }

        //改
        System.out.println("===改===");
        String trim = str.trim();//去除字符串收尾空格，中间空格不会被去除
        String replace = str.replace("a", "t");
        System.out.println(trim + "   " + replace);
        //abc bd   tbc bd

        //查
        String cha = "chaxunzifuchuan";
        System.out.println("===查===");
        int b = cha.indexOf("u");//首次出现u字符串的角标
        int b1 = cha.lastIndexOf("u");//最后一次出现u字符串的角标
        char c = cha.charAt(2);//字符串中角标为2的字符
        boolean a = cha.startsWith("c");
        boolean b2 = cha.startsWith("h", 1);
        boolean d = cha.endsWith("d");
        System.out.println(b + "  " + b1 + " " + c + "  " + a + "  " + b2 + "  " + d + "  ");
        //4  12 a  true  true  false

        //比
        System.out.println("===比===");
        boolean abcdqwe = str.equals("abcdqwe");
        boolean abcdqwe1 = str.equalsIgnoreCase("abcdqwe");
        String aa = "2";
        String bb = "3";
        String cc = "c";
        int i = aa.compareTo(bb); //ASCII编码比较大小，i= 0 时相等
        System.out.println(abcdqwe + "  " + abcdqwe1 + "  " + i);
        //false  false  -1

        //转
        System.out.println("===转===");
        String dd = "4";
        String ee = "3.0";
        String ff = "2.0";
        int i1 = Integer.parseInt(dd);
//        long l = Long.parseLong(ee, 10);//radix 进制
        double v = Double.parseDouble(ff);
        System.out.println(i1 + "  " + v);
        //4  2.0
        String zhuan = "asdf";
        char[] chars1 = zhuan.toCharArray();

    }
}
